package rsj.api.user;

import com.rlyy.aibase.db.Dbink;
import com.rlyy.aibase.utils.base.Box;
import com.rlyy.aibase.utils.base.MapNode;
import com.rlyy.aibase.utils.base.ThinkException;
import common.util.BoxUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import rsj.db.PostgresqlConn;
import rsj.log.ModuleEnum;
import rsj.log.OperationLog;
import rsj.log.OperationTypeEnum;
import rsj.service.UserInfoService;

import java.sql.Connection;
import java.sql.SQLException;
@RestController
public class UserUpdate {
	protected static final Logger logger = LoggerFactory.getLogger(UserUpdate.class);
	@Autowired
	private UserInfoService userInfoService;

	@RequestMapping(value = "rsj_sys_userUpdate")
	@OperationLog(description = "修改用户", logType = OperationTypeEnum.UPDATE, logModule = ModuleEnum.USER_MANAGEMENT)
	public Box executeLink(Box in) throws ThinkException {

		MapNode data = in.getMapNode("data");

		Connection conn = PostgresqlConn.getConnection();

		try {
			userInfoService.updateUser(conn, data);
		} catch (SQLException e) {
			logger.error("invoke--->" + in.getApi() + " error "
                    + ", arguments is " + in.toJson() , e);
            //return BoxUtil.errorBox(in,  "错误原因::" + e.getMessage());
            return BoxUtil.errorBox(in,  "服务器忙！" );
		}finally {
            Dbink.close(conn);
        }

		return BoxUtil.successBox(in, "修改成功！");
	}

}
